<?php
class Xemay extends Model {
	private $data;
    function Xemay()
    {     
        parent::Model();
        $this -> getAllData();
    }
    
    function getAllData() {    	
		$this -> data = array();
		$qresult = $this->db->get('xemay_category');
		foreach($qresult -> result() as $row) {
			array_push($this -> data,$row);
		}
    }       
    
    /**
     * This index is not CAT_ID, be carefull
     * @param $index
     * @return unknown_type
     */
    function getSellPriceWithId($index) {
    	return $this -> data[$index] -> GIA_XUAT_CHUNG;
    }
     
    /**
     * This index is not CAT_ID, be carefull
     * @param $index
     * @return unknown_type
     */
    function getBuyPriceWithId($index) {
    	return $this -> data[$index] -> GIA_NHAP_CHUNG;
    } 
    
    /**
     * This index is not CAT_ID, be carefull
     * @param $index
     * @return unknown_type
     */
    function getNameWithId($index) {
    	return $this -> data[$index] -> TEN;
    }
    
    function getColorWithId($index) {
    	return $this -> data[$index] -> MAU;
    }
    
    /**
     *	Return the cat_id of the item with name/color, -1 if not found
     * @param $name
     * @param $color
     * @return unknown_type
     */
    function getIdFromDesc($name,$color) {    	
//    	var_dump($this -> data); echo "<br/>";
//    	var_dump($name); echo "<br/>";
//    	var_dump($color); echo "<br/>";
//    	
//    	die("Here !");
    	foreach($this -> data as $row) {
    		if ( $row -> TEN == $name && $row -> MAU == $color ) {
    			return (string)($row -> CAT_ID);
    		}
    	}	
    	return "-1"; 
    }
    
    function getRow($cat_id) {
//    	var_dump($cat_id);
//    	die('Here 71');
    	$q = $this -> db -> get_where('xemay_category',array('CAT_ID'=>$cat_id));
//    	var_dump($q -> row());
//    	die('Here 74');
    	
    	if ( $q -> num_rows() == 0 ) return null;
    	return $q -> row();
    }
    
    
}
?>